<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>优惠券添加/修改</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css'); }
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,product_add.js,choose.js,imageup.js,DatePicker/WdatePicker.js"); }

    <style>
        .set-text-xh{
            float: none;
        }
        .bz{
            color: #c5c5c5;
        }
        .radio_check
        {
            vertical-align: middle;margin: -2px 2px 0 0

        }
        .order-info-bar {
            height: 33px;
            background: #f1f9ff;
        }
        .order-info-bar .bt-bar {
            display: inline-block;
            color: #8fc0d6;
            height: 33px;
            line-height: 33px;
            padding: 0 20px;
            font-size: 13px;
        }


    </style>
</head>
<body>

<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td"  valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td ">
            <form method="post" name="product_frm" id="product_frm">
                <div class="cfg-header-bar">
                    <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                </div>
                <div class="manage-nr mt-1">
                    <div class="product-add-div">
                        <ul class="info-item-block">
                            <li><span class="item-hd">小程序模板：</span> <div class="item-bd"><span class="item-text ">综合版小程序</span></div></li>
                            <li><span class="item-hd">显示位置：</span> <div class="item-bd"><span class="item-text ">小程序首页 > 导航上方</span></div></li>
                            <li><span class="item-hd">显示类型：</span> <div class="item-bd"><span class="item-text ">多图</span></div></li>
                            <li>
                                <span class="item-hd">可使用产品：</span>
                                <div class="item-bd">
                                    <div class="typeid_9999" >
                                     <a href="javascript:;" class="btn btn-primary radius size-S ml-10" onclick="add_product.getaddproduct(this,'.attr-sel',1)" title="选择产品">选择产品</a>
                                    </div>
                                   <div class="apply-tab-wrap typeid_9999" style="display:block" >
                                    <div class="action-bar clearfix">
                                        <div class="item-nr">
                                              <span class="select-box w200">
                                                  <select id="search_typeid" class="select" onchange="togStatus(this)">
                                                      <option value="0"> 全部</option>
                                                      {loop $models $m}
                                                      <option value="{$m['id']}"> {$m['modulename']}</option>
                                                      {/loop}
                                                  </select>
                                              </span>
                                            <input type="text" class="input-text w300 ml-10" id="search_input" value="" placeholder="请输入关键词">
                                            <a class="btn btn-primary radius ml-10" href="javascript:;" id="search_btn">搜索</a>
                                        </div>
                                    </div>
                                    <div class="apply-tab-block mt-10 pr-20">
                                        <table class="table table-border table-bordered" id="dlg_tb">
                                            <tr>
                                                <th width="50">排序</th>
                                                <th width="150">产品编号</th>
                                                <th>产品类型</th>
                                                <th>产品名称</th>
                                                <th width="150">管理</th>
                                            </tr>
                                        </table>
                                        <div class="btn-block" >
                                            <div class="pm-btm-msg" id="page_info">

                                            </div>
                                        </div>
                                    </div>
                                  </div>
                                </div>
                             </li>
                        </ul>
                </div>

            </form>
        </td>
    </tr>
</table>

<script>

    add_product = {
        getsetmodeltype:function(dom,selector)
        {

            var  models= [];
            $(selector+" input:hidden").each(function(index,obj){

                models.push($(obj).val());
            });
            models = models.join('_');
            CHOOSE.setSome("选择品类",{loadWindow:window,loadCallback:add_product.listgetsetmodeltype},SITEURL+'coupon/admin/coupon/dialog_setmodeltype?models='+models+'&selector='+encodeURI(selector),1);
        },
        listgetsetmodeltype:function(result,bool)
        {
            var data=result.data;
            var html = '';
            $.each(data,function(index,model){
                html +='<span  style="display: inline-block; float: none"><s onclick="$(this).parent(\'span\').remove()"></s>'+model.modulename+'<input type="hidden" name="models[]" value="'+model.id+'"></span>';
            })
            $('.modules-sel').html(html)
        },
        getaddproduct:function()
        {
            var params={loadCallback: add_product.listchooseProduct,loadWindow:window};
            var url= SITEURL+'share/admin/wxxcx/add_product';
            ST.Util.showBox('指定产品',url,'900','600',null,null,document,params);
        },
        listchooseProduct:function(){
            get_product_list();//加载列表
        }
    };
    $(document).ready(function(){
        $('input[name=isnever]').click(function(){
            var val = $(this).val();
            if(val>0)
            {
                $('.isneverspan').show();
            }
            else
            {

                $('.isneverspan').hide();
            }
        });
        $('input[name=typeid]').click(function(){
            var val = $(this).val();
            if(val==1)
            {
                $('.typeid_1').css('display','inline-block')
                $('.typeid_9999').hide();
            }
            else if(val==9999)
            {
                $('.typeid_9999').each(function(index,obj){
                    if($(obj).hasClass('apply-tab-wrap'))
                    {
                        $(obj).show()
                    }
                    else
                    {
                        $(obj).css('display','inline-block')
                    }
                })
                $('.typeid_1').hide();
            }
            else
            {
                $('.typeid_1').hide();
                $('.typeid_9999').hide();

            }


        })

        $('#amount0').blur(function () {
            var val = parseInt($(this).val());
            if (isNaN(val)) {
                val = '';
            } else {
                val = Math.abs(val);
                if (val > 99999) {
                    val = 99999;
                }
            }
            $(this).val(val);
        });

        $('#amount1').blur(function () {
            var val = parseFloat($(this).val());
            if (isNaN(val)) {
                val = '';
            } else {
                val = Math.abs(val);
                if (val >=10) {
                    val = 9.9;
                }
            }
            $(this).val(val);
        });

        $('#samount').blur(function () {
            var val = parseInt($(this).val());
            if (isNaN(val)) {
                val = '';
            } else {
                val = Math.abs(val);
                if (val >= 1000000) {
                    val = 999999;
                }
            }
            $(this).val(val);
        });


    });


</script>


<script>

    $(function(){
        //日历选择
        $(".choosetime").click(function(){
            WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d',maxDate: '#{%y+2}-%M-%d'})
        });
        get_product_list();
        $('#search_btn').click(function(){
            get_product_list();

        })


    })

</script>



<!--    产品信息-->
<script>

    function   togStatus(obj)
    {
        get_product_list();
    }

    function get_product_list()
    {
        var keyword = $("#search_input").val();
        var typeid = $('#search_typeid').val();
        $.ajax({
            type:'get',
            dataType:'json',
            data:{page:1,keyword:keyword,typeid:typeid},
            url:  SITEURL+"share/admin/wxxcx/pro_list",
            success:function(result)
            {
                genList(result);

            }
        })
    }

    function loadProducts(page)
    {
        var typeid = $('#search_typeid').val();
        var url = SITEURL+"share/admin/wxxcx/pro_list";
        var keyword = $("#search_input").val();
        $.ajax({
            type: "get",
            url: url,
            dataType: 'json',
            data: {page: page,keyword:keyword,typeid:typeid},
            success: function (result, textStatus){
                genList(result);
            }
        });
    }


    function genList(result)
    {
        var html='';
        for(var i in result.lists)
        {
            var row=result.lists[i];
            html+='<tr class="tb-item">' +

                '<td><input type="text" class="row-edit-txt" value="'+row["displayorder"]+'" onblur="updateField(this,'+row["id"]+')"></td>'+
                '<td>'+row['bh']+'</td>'+
                '<td>'+row['typename']+'</td>'+
                '<td>'+row['protitle']+'</td>'+
                '<td><a class="delete" href="javascript:;" onclick="delRow(this,'+row.id+')" >移除</a></td></tr>';
        }

        $("#dlg_tb .tb-item").remove();
        $("#dlg_tb").append(html);

        var pageHtml = ST.Util.page(result.pagesize, result.page, result.total, 5);
        $("#page_info").html(pageHtml);
        $("#page_info a").click(function () {
            var page = $(this).attr('page');
            loadProducts(page);
        });
    }

    function delRow(dom,id)
    {

        Ext.Ajax.request({
            url   :  SITEURL+"share/admin/wxxcx/add_product/action/del",
            method  :  "POST",
            params:{id:id},
            success  :  function(response, opts)
            {
                var text = response.responseText;
                if(text=='ok')
                {
                    get_product_list();
                }
                else
                {
                    ST.Util.showMsg("{__('norightmsg')}",5,1000);
                }
            }});
    }

    function updateField(ele,id)
    {
        var value=Ext.get(ele).getValue();
        var field = 'displayorder';
        Ext.Ajax.request({
            url   :  SITEURL+"share/admin/wxxcx/index/action/update",
            method  :  "POST",
            datatype  :  "JSON",
            params:{id:id,field:field,val:value},
            success  :  function(response, opts)
            {
                if(response.responseText=='ok')
                {
                    get_product_list();
                }
                else
                {
                    ST.Util.showMsg("{__('norightmsg')}",5,1000);
                }
            }});


    }


</script>




</body>
</html>
